package com.beasts.ant.page.repository.content;

import com.beasts.ant.page.entity.content.ApArticle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 内容管理 - 文章管理
 *
 * @author Locker
 * @date 25/06/2018 10:26 AM
 * @since 1.0
 */
public interface ArticleRepository extends JpaRepository<ApArticle, String>, JpaSpecificationExecutor<ApArticle> {

//    @Select("select p from ap_home_page p where p.page_order=#{order}")
//    List<APHomePage> queryByPageOrder(String order);

    /**
     * 根据 id 批量删除
     *
     * @param ids
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = " delete from ApArticle e where e.id in (:ids) ")
    int deleteByIds(@Param("ids") List<String> ids);

    /**
     * 更新
     */
    @Modifying
    @Transactional
    @Query(value = " update ApArticle e set e.title = ?2 where e.id = ?1 ")
    int updateById(
            String id,
            String title
    );

}
